"use strict";
module.exports = (app) => {
  const { STRING, BOOLEAN, INTEGER } = app.Sequelize;
  const SysMenu = app.model.define("sys_menu", {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: "主键id，自增",
    },
    parentId: {
      type: INTEGER,
      defaultValue: 0,
      comment: "父菜单ID 一级菜单为0",
    },
    perm: {
      type: STRING(50),
      allowNull: false,
      unique: true,
      comment: "权限值",
    },
    title: {
      type: STRING(50),
      allowNull: false,
      comment: "菜单名称",
    },
    name: {
      type: STRING(50),
      comment: "路由名称",
    },
    path: {
      type: STRING(50),
      comment: "路由路径",
    },
    component: {
      type: STRING(100),
      comment: "组件",
    },
    icon: {
      type: STRING(100),
      comment: "图标",
    },
    type: {
      type: INTEGER,
      defaultValue: 0,
      comment: '菜单类型  0目录 1菜单  2按钮 3外部链接'
    },
    status: {
      type: BOOLEAN,
      defaultValue: true,
      comment: "状态 true：有效  false：冻结",
    },
    sort: {
      type: INTEGER,
      comment: '排序'
    },
  });

  SysMenu.associate = () => {
    // 与角色表是多对多关系
    app.model.SysMenu.belongsToMany(app.model.SysRole, {
      through: app.model.SysRoleMenu,
      foreignKey: "menuId",
      otherKey: "roleId",
    });
  };

  return SysMenu;
};
